#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

const int max_board_size = 64;
#define WARNING cout << "WARNING!" << endl

struct SubGraph
{
  int x;
  int y;
  int length;
};

struct Board
{
  int boundary[max_board_size][2]; //左右边界
  int length_of_side; //边长
  int leavings; //剩余
  int count; //子图的数量
  int& solution_count;
  SubGraph* graphes;

  Board( int length, int& maxcount ): solution_count( maxcount )
  {
    this->length_of_side = length;
    this->leavings = length * length;
    this->count = 0;
    memset( boundary, 0, sizeof( boundary ) );
    for( int i = 0; i < length_of_side; i++ )
    {
      boundary[i][1] = length_of_side;
    }
    graphes = new SubGraph[leavings];
  }

  ~Board()
  {
    delete[] graphes;
  }

  //把坐标在(x,y)且边长为s的子图分割出来
  inline bool test( int y, int d, int s )
  {
    //if( c.x + s > length_of_side || c.y + s > length_of_side ) return false;
    //边一定是平坦的
    int x0 = boundary[y][d];
    for( int i = y; i < y + s; i++ )
    {
      if( boundary[i][d] != x0 ) return false;
      if( boundary[i][1] - boundary[i][0] < s ) return false;
    }
    return true;
  }
  
  inline void cut( int y, int d, int s )
  {
    int w = ( d == 0 ) ? s : -s;
    for( int i = y; i < y + s; i++ )
    {
      boundary[i][d] += w;
    }
    leavings -= s * s;
    SubGraph& g = graphes[count++];
    g.length = s;
    g.x = ( d == 0 ) ? boundary[y][0] : boundary[y][1] - s;
    g.y = y;
  }

  inline void tie( int y, int d, int s )
  {
    int w = ( d == 0 ) ? -s : s;
    for( int i = y; i < y + s; i++ )
    {
      boundary[i][d] += w;
    }
    leavings += s * s;
    count--;
  }

  void split( int len, int top )
  {
    if( count >= solution_count )
    {
      return;
    }
    
    if( len == 1 )
    {
      if( solution_count > count + leavings )
      {
        solution_count = count + leavings;
        cout << "SLOVEA: " << solution_count << endl;
        for( int i = 0; i < count; i++ )
        {
          cout << graphes[i].x << " " << graphes[i].y << " " << graphes[i].length << endl;
        }
      }
      return;
    }

    if( leavings == 0 )
    {
      if( solution_count > count )
      {
        solution_count = count;
        cout << "SLOVEB: " << solution_count << endl;
      }
      return;
    }

    for( ; top <= length_of_side - len; top++ )
    {
      for( int d = 0; d < 2; d++ )
      {
        if( !test( top, d, len ) ) continue;
        cut( top, d, len );
        split( len, top );
        tie( top, d, len );
      }
    }
    
    split( len - 1, 0 );
  }
};

void slove( int n )
{
  int solution = n * n + 1;
  int start = ( n % 2 == 0 ) ? n / 2 : n / 2 + 1;
  for( int i = start; i < n; i++ )
  {
    Board t( n, solution );
    if( !t.test( 0, 0, i ) ) WARNING;
    else t.cut( 0, 0, i );
        
    for( int j = 0; j < i / ( n - i ); j++ )
    {
      if( !t.test( j * ( n - i ), 0, n - i ) ) WARNING;
      else t.cut( j * ( n - i ), 0, n - i );
      if( !t.test( i, 0, n - i ) ) WARNING;
      else t.cut( i, 0, n - i );
    }
    t.split( n - i, 0 );
  }
}

int main()
{
  int cases = 0;
  cin >> cases;
  while( cases-- )
  {
    int n = 0;
    cin >> n;
    slove( n );
  }
//  system( "time /t" );
//  for( int i = 2; i <= 50; i++ )
//  {
//    cout << "---------process " << i << "---------" << endl;
//    slove( i );
//  }
//  system( "time /t" );  
  return 0;
}
